package com.pactera.service;

import java.net.URL;

import org.apache.log4j.Logger;

import com.pactera.consts.Const;

/**
 * 短信接口发送类 TODO zhanglj 2016-8-5
 */
public class SmsService {
	private static Logger logger = Logger.getLogger(SmsService.class);

	public static int sendSms(String wsdlUrl, String spCode, String user,
			String pwd, String si, String phone, String msgContent) {
		logger.info("短信内容：" + msgContent);
		int result = Const.SMS_SEND_FAILED;
//		return Const.SMS_SEND_SUCCESS;
		try {
			org.codehaus.xfire.client.Client client2 = new org.codehaus.xfire.client.Client(
					new URL(wsdlUrl));
			Object[] ret = client2.invoke("sendSms", new Object[] { spCode,
					user, pwd, si, phone, msgContent, "8", "5" });
			logger.info("--------------返回的短信状态码：" + ret[0]);
			// 如果状态的不是ER001-7,则短信发送成功
//			ER006是用户名密码不对   ER003电话号码有误或识别不了
			if (!ret[0].equals("ER001") && !ret[0].equals("ER002")
					&& !ret[0].equals("ER003") && !ret[0].equals("ER004")
					&& !ret[0].equals("ER005") && !ret[0].equals("ER006")
					&& !ret[0].equals("ER007")) {
				result = Const.SMS_SEND_SUCCESS;
				logger.info("--------------短信发送成功--------------");
			} else {
				logger.info("--------------短信发送失败--------------");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("--------------短信发送异常");
		} finally {
			return result;
		}

	}

}
